package com.hmdp.config;

import com.hmdp.utils.LoginInterceptor;
import com.hmdp.utils.TokenRefreshInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 配置类：配置拦截器
 */

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //刷新缓存中用户信息的有效期
        registry.addInterceptor(new TokenRefreshInterceptor(redisTemplate)).excludePathPatterns(
                "/mq/test/send","/ai/chat"
        ).order(0);//先执行
        //完成拦截或放行
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
                "/mq/test/send","/ai/chat","/user/code","/user/login","/blog/hot","/shop.**","/shop-type/**","/upload/**","/voucher/**"
        ).order(1);//添加拦截器，配置不需要拦截的路径  后执行
    }
}
